fastCSharp.Ace=function()
	{
	this.GetArgument(this.Argument=arguments[0],{Id:null,MinLength:null,MaxHeight:0,FontSize:12,Code:'',Mode:'csharp',Theme:'eclipse',IsWrap:1,IsReadOnly:0});
	(this.OnChange=fastCSharp.Event()).Add(fastCSharp.ThisFunction(this,this.Resize));
	};
fastCSharp.Copy(fastCSharp.Ace,{
Identity:0,
Modes:[
	{type:'C#',mode:'csharp'},
	{type:'C/C++',mode:'c_cpp'},
	{type:'Java',mode:'java'},
	{type:'Javascript',mode:'javascript'},
	{type:'PHP',mode:'php'},
	{type:'Python',mode:'python'},
	{type:'Ruby',mode:'ruby'},
	{type:'Haskell',mode:'haskell'},
	{type:'Scala',mode:'scala'},
	{type:'Go',mode:'golang'},
	{type:'VB',mode:'vbscript'},
	{type:'Xml',mode:'xml'},
	{type:'Css',mode:'css'},
	{type:'Sql',mode:'sql'},
	{type:'Pascal',mode:'pascal'}],
CheckIE6:function()
	{
	if(fastCSharp.IsIE)
		{
		var Version=navigator.appVersion.match(/MSIE\s+(\d+)/);
		if(Version&&Version.length==2&&parseInt('0'+Version[1],10)<7)
			{
			this.IsIE6=1;
			return;
			}
		}
	fastCSharp.OnLoad(this.Load,this,1);
	fastCSharp.OnModule(['ace.ace'],fastCSharp.ThisFunction(this,this.Show),1,1);
	},
Load:function()
	{
	fastCSharp.PageView.OnSet.Add(fastCSharp.ThisFunction(this,this.Show));
	},
Show:function()
	{
	if(window.ace)
		{
		for(var Elements=fastCSharp.$Name('ace').GetElements(),Index=0;Index-Elements.length;++Index)
			{
			if(!fastCSharp.$ElementName(Elements[Index],'htmleditor'))
				{
				var Div=Elements[Index];
				if(Div.offsetHeight)
					{
					var Mode=fastCSharp.$Attribute(Div,'mode');
					if(!Div.id&&Mode)	new fastCSharp.Ace({Id:Div.id='fastCSharpAce'+(++this.Identity),Code:fastCSharp.$Text(Div.childNodes[0]).replace(/\xA0/g,' '),Mode:Mode,IsReadOnly:1}).Show();
					}
				}
			}
		}
	}
		});

fastCSharp.Ace.Inherit(fastCSharp.BaseFunction,{
Check:function()
	{
	if(fastCSharp.$Id(this.Id).Attribute('ace'))	return this;
	var Ace=new fastCSharp.Ace(this.Argument);
	Ace.Show();
	return Ace;
	},
Show:function()
	{
	var Div=fastCSharp.$Id(this.Id),Height=this.IsReadOnly?0:Div.Height();
	(this.Editor=ace.edit(this.Id)).setFontSize(this.FontSize);
	var LineHeight=this.Editor.renderer.lineHeight||14;
	if(this.IsReadOnly)
		{
		this.MinLength=1;
		Div.Css('height',(((this.LastLength=this.Editor.getSession().getLength())+(this.IsWrap?0:1))*LineHeight+2)+'px');
		}
	else	{
		if(!this.MinLength)	this.MinLength=Math.floor((Height+LineHeight-1)/LineHeight);
		Div.Css('height',(((this.LastLength=this.MinLength)+(this.IsWrap?0:1))*LineHeight+2)+'px');
		}
	var Session=this.Editor.getSession();
	Session.setMode('ace/mode/'+this.Mode);
	Session.setUseWrapMode(this.IsWrap);
	Session.on('change',this.OnChange);
	Session.on('changeFold',this.OnChange);
	this.Editor.setTheme('ace/theme/'+this.Theme);
	if(this.Code!=null)	this.Editor.setValue(this.Code);
	this.Editor.setReadOnly(this.IsReadOnly);
	this.Editor.moveCursorTo(0,0);
	if(!this.IsReadOnly)	this.Editor.focus();
	Div.Attribute('ace','1');
	},
Set:function(Value)
	{
	var Session=this.Editor.getSession();
	if(Value.Mode)	Session.setMode('ace/mode/'+(this.Mode=Value.Mode));
	if(Value.Theme)	Session.setTheme('ace/theme/'+(this.Theme=Value.Theme));
	if(Value.Code!=null)	this.Editor.setValue(Value.Code);
	this.Editor.moveCursorTo(0,0);
	if(!this.IsReadOnly)	this.Editor.focus();
	},
Resize:function()
	{
	var Length=this.Editor.getSession().getScreenLength();
	if(this.MaxHeight)
		{
		var MaxLength=Math.floor(((this.MaxHeight<0?(fastCSharp.$Height()+this.MaxHeight):this.MaxHeight)-2)/this.Editor.renderer.lineHeight)-(this.IsWrap?0:1);
		if(Length>MaxLength)	Length=MaxLength;
		}
	if(Length<this.MinLength)	Length=this.MinLength;
	if(Length!=this.LastLength)
		{
		fastCSharp.$Id(this.Id).Css('height',(((this.LastLength=Length)+(this.IsWrap?0:1))*this.Editor.renderer.lineHeight+2)+'px');
		this.Editor.resize();
		}
	}
		});
fastCSharp.Ace.CheckIE6();